﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="WinRTSock.Test.TestPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinRTSock.Test"
    xmlns:common="using:WinRTSock.Test.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <x:String x:Key="PageTitle">Run WinRTSock Tests</x:String>
        <DataTemplate x:Key="TestItemTemplate">
            <Grid Margin="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="400" />
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding TestName}" VerticalAlignment="Center" HorizontalAlignment="Left" />
                <Button Content="Run" Grid.Column="1"  Command="{Binding Command}" />
                <Ellipse Grid.Column="2" Width="20" Height="20" Fill="{Binding ResultIndicator, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                <TextBlock Text="{Binding Notes, Mode=TwoWay}" Grid.Column="3" HorizontalAlignment="Left" VerticalAlignment="Center" />
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource PageTitle}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>

        <ListBox Grid.Row="1" Margin="116,0,116,46" ItemsSource="{Binding Items}" ItemTemplate="{StaticResource TestItemTemplate}" />

        <Grid Grid.Row="2" Margin="116,0,116,46">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Ellipse Grid.Column="0" Width="40" Height="40" Fill="{Binding TestSuiteResultIndicator, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" />
            <TextBlock Text="Total number of tests: " Grid.Column="1" VerticalAlignment="Center" Margin="10" />
            <TextBlock Text="{Binding TotalTestCount}" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" />
            <TextBlock Text="Succeeded: " Grid.Column="3" VerticalAlignment="Center" Margin="10" />
            <TextBlock Text="{Binding SucceededTestCount}" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" />
            <TextBlock Text="Failed: " Grid.Column="5" VerticalAlignment="Center" Margin="10" />
            <TextBlock Text="{Binding FailedTestCount}" Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" />
            <Button Content="Run all" Grid.Column="7" HorizontalAlignment="Right" Click="RunAll_Click" />
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
